﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Noebe.Consistency;
using Pixysoft.Framework.Verifications;

namespace Pixysoft.Framework.Noebe.Orm.Core
{
    class CstOrmTransaction : CstOrmSession, ICstOrmTransaction
    {
        ICstNoebeCommand command = null;

        IOrmQuery query = null;

        public CstOrmTransaction(ICstNoebeCommand command, string groupCode)
            : base(command, groupCode)
        {
            this.command = command;

            this.query = new OrmQuery(command);
        }

        public void Begin()
        {
            command.Begin();
        }

        public void Commit()
        {
            command.Commit();
        }

        public void Rollback()
        {
            command.Rollback();
        }


        public T SelectByUpk<T>(object value)
        {
            return query.SelectByUpk<T>(value);
        }

        public bool Contains<T>(object value)
        {
            return query.Contains<T>(value);
        }

        public List<T> SelectAll<T>()
        {
            return query.SelectAll<T>();
        }

        public List<T> Select<T>()
        {
            return query.Select<T>();
        }

        public string QueryString
        {
            get
            {
                return query.QueryString;
            }
            set
            {
                query.QueryString = value;
            }
        }

        public Dictionary<string, object> Parameters
        {
            get
            {
                return query.Parameters;
            }
        }


        public override void SetCommand(INoebeCommand command)
        {
            throw Exceptions.UnexpectedResultException("cst orm noebe not support noebecommand. use setCommand(ICstNoebeCommand command) instead.");
        }

        public override void SetCstCommand(ICstNoebeCommand command)
        {
            this.command = command;
            base.SetCstCommand(command);
        }

    }
}
